package org.asiainfo.system.service.impl;

import org.asiainfo.common.mybatis.stream.core.page.TableDataInfo;
import org.asiainfo.common.mybatis.stream.core.page.PageQuery;
import org.asiainfo.system.domain.vo.SysOperationLogVo;
import org.asiainfo.system.domain.bo.SysOperationLogBo;
import org.asiainfo.system.domain.SysOperationLog;
import org.asiainfo.system.service.SysOperationLogService;
import org.springframework.stereotype.Service;
import org.asiainfo.common.core.utils.MapstructUtils;
import lombok.extern.slf4j.Slf4j;
import com.mybatisflex.core.query.QueryWrapper;
import lombok.RequiredArgsConstructor;
import com.mybatisflex.spring.service.impl.ServiceImpl;
import org.asiainfo.system.mapper.SysOperationLogMapper;
import com.mybatisflex.core.paginate.Page;

import java.util.Map;
import java.util.Collection;
import java.util.List;

/**
 * 操作日志记录(SysOperationLog)表服务实现类
 *
 * @author dotor-ww
 */
@Service
@RequiredArgsConstructor
@Slf4j
public class SysOperationLogServiceImpl extends ServiceImpl<SysOperationLogMapper, SysOperationLog> implements SysOperationLogService {

    /**
     * 查询
     *
     * @param sysOperationLogBo 筛选条件
     * @return 查询结果
     */
    @Override
    public List<SysOperationLogVo> queryList(SysOperationLogBo sysOperationLogBo) {
        QueryWrapper query = query();
        return listAs(query, SysOperationLogVo.class);
    }

    /**
     * 通过operationId查询单条数据
     *
     * @param operationId 主键
     * @return 实例对象
     */
    @Override
    public SysOperationLogVo queryById(Long operationId) {
        return getOneAs(query().eq(SysOperationLog::getOperationId, operationId), SysOperationLogVo.class);
    }

    /**
     * 分页查询
     *
     * @param sysOperationLogBo 筛选条件
     * @param pageQuery         分页对象
     * @return 查询结果
     */
    @Override
    public TableDataInfo<SysOperationLogVo> queryPageList(SysOperationLogBo sysOperationLogBo, PageQuery pageQuery) {
        QueryWrapper query = query();
        pageQuery.buildOrder(query);
        Page<SysOperationLogVo> page = pageAs(pageQuery.buildPage(), query, SysOperationLogVo.class);
        return TableDataInfo.build(page);
    }

    /**
     * 新增数据
     *
     * @param sysOperationLogBo 实例对象
     * @return 实例对象
     */
    @Override
    public Boolean insertByBo(SysOperationLogBo sysOperationLogBo) {
        SysOperationLog sysOperationLog = MapstructUtils.convert(sysOperationLogBo, SysOperationLog.class);
        return save(sysOperationLog);
    }

    /**
     * 修改数据
     *
     * @param sysOperationLogBo 实例对象
     * @return 实例对象
     */
    @Override
    public Boolean updateByBo(SysOperationLogBo sysOperationLogBo) {
        SysOperationLog sysOperationLog = MapstructUtils.convert(sysOperationLogBo, SysOperationLog.class);
        return updateById(sysOperationLog);
    }

    /**
     * 通过主键删除数据
     *
     * @param operationIds 主键
     * @return 是否成功
     */
    @Override
    public Boolean deleteWithValidByIds(Collection<Long> operationIds) {
        return removeByIds(operationIds);
    }

    /**
     * 清空数据
     *
     * @return 删除是否成功
     */
    @Override
    public Boolean deleteAll() {
        return remove(query());
    }
}
